package com.yuneec.fly.dialogs;

import android.annotation.SuppressLint;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.TextView;

import com.yuneec.fly.R;

/**
 * Created by jw.gu on 2016/6/25.
 */
@SuppressLint("ValidFragment")
public class ConfirmDialogWithoutSeekbar extends BaseDialogFragment {
    private OnCancelListener onCancelListener;
    private OnConfirmListener onConfirmListener;
    private String message;


    public ConfirmDialogWithoutSeekbar(String message, OnConfirmListener onConfirmListener, OnCancelListener onCancelListener) {
        super();
        this.onConfirmListener = onConfirmListener;
        this.onCancelListener = onCancelListener;
        this.message = message;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        setCancelable(false);
        View view = inflater.inflate(R.layout.dialog_confirm, container);

        ((TextView) view.findViewById(R.id.dialogMessage)).setText(message);
        View.OnClickListener cancelListener = new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onCancelListener != null) {
                    onCancelListener.onCancel(ConfirmDialogWithoutSeekbar.this);
                }
                dismiss();
            }
        };
        view.findViewById(R.id.cancelBtn).setOnClickListener(cancelListener);
        view.findViewById(R.id.confirmBtn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onConfirmListener != null) {
                    onConfirmListener.onConfirm(ConfirmDialogWithoutSeekbar.this);
                } else {
                    dismiss();
                }
            }
        });
        return view;
    }

}
